<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>823680621</title>
</head>
<body>
	
</body>
<script>
	var cvs=document.createElement("canvas");
	cvs.style.body="2px solid red";
	var ctx =cvs.getContext("2d");
	ctx.fillStyle="yellow";
	ctx.fillRect(0,0,300,150);
	ctx.fillStyle="blue";
	ctx.fillRect(50,50,100,150);
	document.body.appendChild(cvs);

	var dataURL=cvs.toDataURL('image/jpeg',0.5);//0.5模糊
	console.log(dataURL);


/*
	document.onclick=function(){
 		var img=document.createElement("img");
 		img.src=dataURL;
 		 document.body.appendChild(img);
 		}
*/
</script>
</html>